package com.rmy.publish.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.rmy.common.annotation.Log;
import com.rmy.common.core.controller.BaseController;
import com.rmy.common.core.domain.AjaxResult;
import com.rmy.common.enums.BusinessType;
import com.rmy.publish.domain.MipsProgramInfo;
import com.rmy.publish.service.IMipsProgramInfoService;
import com.rmy.common.utils.poi.ExcelUtil;
import com.rmy.common.core.page.TableDataInfo;

/**
 * 节目管理Controller
 *
 * @author rmy
 * @date 2023-05-21
 */
@RestController
@RequestMapping("/publish/mipsProgramInfo")
public class MipsProgramInfoController extends BaseController
{
    @Autowired
    private IMipsProgramInfoService mipsProgramInfoService;

    /**
     * 查询节目管理列表
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MipsProgramInfo mipsProgramInfo)
    {
        startPage();
        List<MipsProgramInfo> list = mipsProgramInfoService.selectMipsProgramInfoList(mipsProgramInfo);
        return getDataTable(list);
    }

    /**
     * 导出节目管理列表
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:export')")
    @Log(title = "节目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MipsProgramInfo mipsProgramInfo)
    {
        List<MipsProgramInfo> list = mipsProgramInfoService.selectMipsProgramInfoList(mipsProgramInfo);
        ExcelUtil<MipsProgramInfo> util = new ExcelUtil<MipsProgramInfo>(MipsProgramInfo.class);
        util.exportExcel(response, list, "节目管理数据");
    }

    /**
     * 获取节目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:query')")
    @GetMapping(value = "/{programId}")
    public AjaxResult getInfo(@PathVariable("programId") Long programId)
    {
        return AjaxResult.success(mipsProgramInfoService.selectMipsProgramInfoByProgramId(programId));
    }

    /**
     * 新增节目管理
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:add')")
    @Log(title = "节目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MipsProgramInfo mipsProgramInfo)
    {
        mipsProgramInfo.setCreateBy(getUsername());
        return toAjax(mipsProgramInfoService.insertMipsProgramInfo(mipsProgramInfo));
    }

    /**
     * 修改节目管理
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:edit')")
    @Log(title = "节目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MipsProgramInfo mipsProgramInfo)
    {
        mipsProgramInfo.setUpdateBy(getUsername());
        return toAjax(mipsProgramInfoService.updateMipsProgramInfo(mipsProgramInfo));
    }

    /**
     * 删除节目管理
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:remove')")
    @Log(title = "节目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{programIds}")
    public AjaxResult remove(@PathVariable Long[] programIds)
    {
        return toAjax(mipsProgramInfoService.deleteMipsProgramInfoByProgramIds(programIds));
    }


    /**
     * 根据节目编码查询
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:query')")
    @GetMapping(value = "/getInfoByProgramCode/{programCode}")
    public AjaxResult getInfoByProgramCode(@PathVariable("programCode") String programCode)
    {
        return AjaxResult.success(mipsProgramInfoService.selectMipsProgramInfoByProgramCode(programCode));
    }


    /**
     * 插入节目数据
     */
    @PreAuthorize("@ss.hasPermi('publish:mipsProgramInfo:add')")
    @Log(title = "节目数据", businessType = BusinessType.INSERT)
    @PostMapping("/insertProgram")
    public AjaxResult insertProgram(@RequestBody MipsProgramInfo mipsProgramInfo)
    {
        return toAjax(mipsProgramInfoService.insertProgram(mipsProgramInfo));
    }

    /**
     * 导出项目
     * @param request
     * @param response
     * @param programCode
     * @param showDataSet
     * @return
     */
    @GetMapping("/exportProject")
    public void exportProject(HttpServletRequest request, HttpServletResponse response,
                                                @RequestParam("programCode") String programCode,
                                                @RequestParam(value = "showDataSet",required = false, defaultValue = "1") Integer showDataSet) throws IOException {
        mipsProgramInfoService.exportProject(request, response, programCode, showDataSet);
    }
}
